package com.seawaterbt.ssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seawaterbt.ssm.config.DataSource;
import com.seawaterbt.ssm.config.DataSourceEnum;
import com.seawaterbt.ssm.entity.CzBasBoiler;
import com.seawaterbt.ssm.entity.CzBasHeatsourceExit;
import com.seawaterbt.ssm.entity.ShengBasCrew;
import com.seawaterbt.ssm.entity.ShengBas_Boiler;
import com.seawaterbt.ssm.mapper.CzBasBoilerMapper;
import com.seawaterbt.ssm.mapper.ShengBasBoilerMapper;
import com.seawaterbt.ssm.service.CzBasBoilerService;
import com.seawaterbt.ssm.service.ShengBasBoilerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhf
 * @since 2019-10-31
 */
@Service
public class ShengBasBoilerServiceImpl extends ServiceImpl<ShengBasBoilerMapper, ShengBas_Boiler> implements ShengBasBoilerService {
    @Autowired
    private CzBasBoilerService czBasBoilerService;
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean saveOrUpdate(ShengBas_Boiler entity) {
        return super.saveOrUpdate(entity);
    }

    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean save(ShengBas_Boiler entity) {
        return super.save(entity);
    }

    @Override
    public void toSend() {
        QueryWrapper<CzBasBoiler> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("code",130981011).or().likeRight("code",130903007);
        List<CzBasBoiler> czlist = czBasBoilerService.list(queryWrapper);
        if (czlist != null){
            for (CzBasBoiler czBasBoiler:czlist){
                ShengBas_Boiler shengBas_boiler = new ShengBas_Boiler();
                shengBas_boiler.setAddTime(czBasBoiler.getCreateTime());
                shengBas_boiler.setBoilerId(czBasBoiler.getCodeProvince());
                shengBas_boiler.setBoilerModel(czBasBoiler.getBoilerModel());
                shengBas_boiler.setBoilerName(czBasBoiler.getName());
                shengBas_boiler.setFactory(czBasBoiler.getFactory());
                if (!StringUtils.isEmpty(czBasBoiler.getCodeProvince())){
                    shengBas_boiler.setHeatSourceId(czBasBoiler.getCodeProvince().substring(0,12));
                }
                shengBas_boiler.setFuelType(czBasBoiler.getFuelType());
                shengBas_boiler.setTonnAge(Double.parseDouble(czBasBoiler.getTonnage()==null?"0.0":czBasBoiler.getTonnage()));
                shengBas_boiler.setHeatType(czBasBoiler.getHeatType());
                shengBas_boiler.setUserFor(czBasBoiler.getUsedFor());
                shengBas_boiler.setUserYear(Integer.parseInt(czBasBoiler.getUsedYear()==null?"0":czBasBoiler.getUsedYear()));
                this.save(shengBas_boiler);
            }
        }
    }
}
